package object;

/**
 * @author:Galen
 * @description: 构造方法
 */
public class Construction {
    public String name;
    private int age;

    /**
     * 定义带有一个参数的构造方法
     * @param name
     */
    public Construction(String name) {
        this.name = name;
    }

    /**
     * 定义带有二个参数的构造方法
     * @param name
     * @param age
     */
    public Construction(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String toString() {
        return "大家好！我叫"+name+",今年"+age+"岁";
    }

    public static void main(String[] args) {
        System.out.println("--------带有一个参数的构造方法--------");
        Construction cons = new Construction("later");
        System.out.println(cons);

        System.out.println("--------带有二个参数的构造方法--------");
        Construction cons2 = new Construction("Galen", 28);
        System.out.println(cons2);
    }
}